load("@py3_deps//:requirements.bzl", "requirement")

py_test(
    name = "make_db_test",
    srcs = [
        "make_db.py",
        "make_db_test.py",
        "model.py",
    ],
    data = [":buckets.yaml"],
    python_version = "PY3",
    deps = [
        requirement("certifi"),
        requirement("chardet"),
        requirement("idna"),
        requirement("ruamel.yaml"),
        requirement("requests"),
        requirement("urllib3"),
    ],
)

py_binary(
    name = "make_db",
    srcs = [
        "make_db.py",
        "model.py",
    ],
    python_version = "PY3",
)

# TODO(rmmh): re-enable when Bazel is fixed.
# https://github.com/bazelbuild/rules_python/issues/14
# py_binary(
#    name = "monitor",
#    srcs = [
#        "monitor.py",
#    ],
#    deps = [
#        requirement("influxdb"),
#        requirement("google-cloud-bigquery"),
#    ],
# )

py_test(
    name = "model_test",
    srcs = [
        "model.py",
        "model_test.py",
        ":package-srcs",
    ],
    python_version = "PY3",
)

py_test(
    name = "stream_test",
    srcs = [
        "stream.py",
        "stream_test.py",
        ":package-srcs",
    ],
    data = [
        "buckets.yaml",
        "schema.json",
    ],
    python_version = "PY3",
    deps = [
        requirement("certifi"),
        requirement("chardet"),
        requirement("idna"),
        requirement("ruamel.yaml"),
        requirement("requests"),
        requirement("urllib3"),
    ],
)

py_test(
    name = "make_json_test",
    srcs = [
        "make_json.py",
        "make_json_test.py",
        "model.py",
        ":package-srcs",
    ],
    data = [
        ":buckets.yaml",
        ":xml_data",
    ],
    python_version = "PY3",
    deps = [
        requirement("ruamel.yaml"),
        requirement("parameterized"),
    ],
)

filegroup(
    name = "package-srcs",
    srcs = glob(
        ["**"],
        exclude = [
            "*.db",
            "*.gz",
        ],
    ),
    visibility = ["//visibility:private"],
)

filegroup(
    name = "all-srcs",
    srcs = [":package-srcs"],
    tags = ["automanaged"],
    visibility = ["//visibility:public"],
)

filegroup(
    name = "buckets",
    srcs = ["buckets.yaml"],
    visibility = ["//:__subpackages__"],
)

filegroup(
    name = "xml_data",
    srcs = glob([
        "testdata/*.xml",
    ]),
)
